package com.yun.zf.common.app.domain;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yun.zf.common.esIndex.BusMo;
import com.yun.zf.common.esIndex.SubwayMo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客户资源需求表
 * </p>
 *
 * @author cj
 * @since 2021-03-30
 */
@TableName("zf_customer_requirement")
@Data
public class ZfCustomerRequirement implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    @NotNull(message = "省级代码不能为空")
    @ApiModelProperty(value = "省级区划代码")
    private Long provinceCode;

    @ApiModelProperty(value = "城市编码")
    @NotNull(message = "城市编码不能为空")
    private Long cityCode;


    @NotNull(message = "客源id不能为空")
    @ApiModelProperty(value = "客源id")
    private Long customerId;


    @NotNull(message = "需求类型不能为空")
    @ApiModelProperty(value = "需求类型1租赁住宅 2租商铺3租写字楼 4买二手房5买新房6买商铺7买写字楼")
    private Integer demandType;

    /**
     * 面积
     */
    @ApiModelProperty(value = "面积范围-隔开")
    private String area;
    @TableField(exist = false)
    private Map<String, Integer> areaRange;


    @ApiModelProperty(value = "预算范围")
    private String budget;
    @TableField(exist = false)

    private Map<String, Integer> budgetRange;

    @ApiModelProperty(value = "预算单位")
    private String unit;

    /**
     * 房源装修情况,mp 毛坯，jian 简装，jing 精装，hz 豪华装修
     */
    @ApiModelProperty(value = "房源装修情况")
    private String fixtures;

    /**
     * 意向居室
     */
    @ApiModelProperty(value = "意向居室范围")
    private String bedrooms;
    @TableField(exist = false)
    private Map<String, Integer> bedroomsRange;

    @ApiModelProperty(value = "意向楼层")
    private String floor;


    @ApiModelProperty(value = "楼龄，填写范围")
    private String buidYear;
    @TableField(exist = false)
    private Map<String, Integer> buidYearRange;
    /**
     * 委托时间
     */
    private Date entrustDate;

    @ApiModelProperty(value = "备注原因")
    private String remark;

    @ApiModelProperty(value = "如果出租必选出租方式1整租，2合租")
    private Integer rentType;

    @ApiModelProperty(value = "商圈")
    private String business;

    @ApiModelProperty(value = "区域")
    private String region;


    @ApiModelProperty(value = "地铁")
    private String subway;

    @ApiModelProperty(value = "公交")
    private String bus;

    @ApiModelProperty(value = "学校")
    private String school;

    @ApiModelProperty(value = "医院")
    private String hospital;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime = new Date();

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date modifiedTime = new Date();

    @TableField(exist = false)
    private List<BusMo>  busMos;

    @TableField(exist = false)
    private List<SubwayMo>  subwayMos;
    public List<BusMo> getBusMos() {

        return JSONArray.parseArray(bus,BusMo.class);
    }

    public void setBusMos(List<BusMo> busMos) {
        this.busMos = busMos;
    }

    public List<SubwayMo> getSubwayMos() {
        return JSONArray.parseArray(subway,SubwayMo.class);
    }

    public void setSubwayMos(List<SubwayMo> subwayMos) {
        this.subwayMos = subwayMos;
    }


    public Map<String, Integer> getAreaRange() {
        Map<String, Integer> map = new HashMap<>();
        map.put("gte", Integer.parseInt(area.split("-")[0]));
        map.put("lte",  Integer.parseInt(area.split("-")[1]));
        return map;
    }

    public void setAreaRange(Map<String, Integer> areaRange) {
        this.areaRange = areaRange;
    }

    public Map<String, Integer> getBudgetRange() {
        Map<String, Integer> map = new HashMap<>();
        map.put("gte", Integer.parseInt(budget.split("-")[0]));
        map.put("lte",  Integer.parseInt(budget.split("-")[1]));
        return map;
    }

    public Map<String, Integer> getBedroomsRange() {
        Map<String, Integer> map = new HashMap<>();
        map.put("gte", Integer.parseInt(bedrooms.split("-")[0]));
        map.put("lte",  Integer.parseInt(bedrooms.split("-")[1]));
        return map;
    }

    public Map<String, Integer> getBuidYearRange() {
        Map<String, Integer> map = new HashMap<>();
        map.put("gte", Integer.parseInt(buidYear.split("-")[0]));
        map.put("lte",  Integer.parseInt(buidYear.split("-")[1]));
        return map;
    }
}
